package com.lcf.system.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.lcf.system.dto.user.LoginDTO;
import com.lcf.system.dto.user.OpenSafeDTO;
import com.lcf.system.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户表(User)表控制层
 *
 * @author lcf
 * @since 2025-02-19 13:27:49
 */
@Tag(name = "登陆")
@RestController
@RequestMapping("auth")
public class AuthController {
    @Resource
    private AuthService authService;

    @PostMapping("login")
    @Operation(summary = "登录")
    public SaTokenInfo login(@RequestBody @Validated LoginDTO login) {
        return authService.login(login);
    }

    @PostMapping("logout")
    @Operation(summary = "登出")
    public void logout() {
        StpUtil.logout();
    }

    /**
     * 二次认证
     */
    @Operation(summary = "二次认证")
    @PostMapping("openSafe")
    public void openSafe(@Validated OpenSafeDTO openSafe) {
        authService.openSafe(openSafe);
    }
}

